<template>
	<view class="main"><!--添加用户-->
		<view class="userInfo">
			<view>
				<view class="tit">信息填写</view>
				<view>为了更好的服务，请填写您的亲人信息</view>
			</view>
			<image src="@/static/images/addCont.png" style="width:260rpx;" mode='widthFix'></image>
		</view>
		<view class="userForm">
			<view class="userInput"><text>真实姓名</text><input placeholder="请输入真实姓名" v-model="userForm.name"></view>
			<view class="userInput"><text>身份证码号</text><input placeholder="请输入身份证码号" v-model="userForm.cardId"></view>
			<view class="userInput"><text>电话号码</text><input placeholder="请输入电话号码" v-model="userForm.mobile"></view>
			
		</view>
		
	

		
		
		<view class="userbtn">
			<view class="btn btn1" @tap="backPage">取消</view>
			<view class="btn btn2" @tap="submit">确认添加</view>
		</view>
		
		
		
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userForm:{
					cardId:"",
					mobile:"",
					name:""
				}
			}
		},
		methods: {
			backPage(){
				this.$tools.backPrePage()
			},
			findCustomerInfoForCardId(){
				return this.$http.findCustomerInfoForCardId({cardId:this.userForm.cardId})
			},
			
			async submit(){
				if(!this.userForm.name){
					this.$tools.msg("请输入真实姓名")
					return;
				}
				if(!this.userForm.cardId){
					this.$tools.msg("请输入身份证码号")
					return;
				}
				if(!this.userForm.mobile){
					this.$tools.msg("请输入电话号码")
					return;
				}
				let yz = await this.findCustomerInfoForCardId();
				console.log(yz)
				if(!yz.info){
					this.$http.addCustomerInfo(this.userForm).then(res=>{
						console.log(res);
						if(res.code==0){
							this.$tools.msg("添加成功！")
							uni.navigateTo({
								url:'/pages/followUser/followUser'
							})
						}
					})
				}
				
				return;
				
				
				
				
				
			}
			
		}
	}
</script>

<style scoped lang="scss">
	@import url("@/css/app.scss");
	
	.main{
		background-color:#e7fcf5;
		box-sizing: border-box;
		min-height: 100vh;
	}
</style>
